from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QDialog, QLabel, QLineEdit, QVBoxLayout, QPushButton
from PyQt5.QtGui import QIntValidator


class SettingParams:
    def __init__(self, first, second, third, successListener):
        self.first = first
        self.second = second
        self.third = third
        self.successListener = successListener


def CreateSettingWindow(screen, setting_Params):
    win = QDialog()
    win.setWindowFlags(Qt.WindowCloseButtonHint)
    win.setWindowTitle('设置')
    width = 400
    height = 300
    win.setGeometry((screen.width - width) / 2, (screen.height - height) / 2, width, height)

    outline_vg = QVBoxLayout()

    text_first = QLabel("队列1的时间片大小: ")
    outline_vg.addWidget(text_first)

    input_first = QLineEdit("{}".format(setting_Params.first))
    input_first.setValidator(QIntValidator())
    outline_vg.addWidget(input_first)

    text_second = QLabel("队列2的时间片大小: ")
    outline_vg.addWidget(text_second)

    input_second = QLineEdit("{}".format(setting_Params.second))
    input_second.setValidator(QIntValidator())
    outline_vg.addWidget(input_second)

    text_third = QLabel("队列3的时间片大小: ")
    outline_vg.addWidget(text_third)

    input_third = QLineEdit("{}".format(setting_Params.third))
    input_third.setValidator(QIntValidator())
    outline_vg.addWidget(input_third)

    ok_button = QPushButton("确定")
    ok_button.clicked.connect(
        lambda: setting_Params.successListener(win, input_first.text(), input_second.text(), input_third.text()))
    outline_vg.addWidget(ok_button)

    outline_vg.addStretch()
    win.setLayout(outline_vg)
    return win
